<?php

/*----------------------------------------------+
|  MaxForum					|
|  ===========================================	|
|  By Majd Almontaser				|
|  Released under the License GNU v3.0		|
|  http://www.Max4Dev.com			|
|  ===========================================	|
|  Ttmtt Team - http://www.liioiil.com		|
+-----------------------------------------------*/

if (!defined('MAX_ON')){
	echo "<h1>ACCESS DENIED</h1>You cannot access this file directly.";
	exit();
}

$_GET['pg']	= (int) $_GET['pg'];
$page		= ($_GET['pg'] == 0 || $_GET['pg'] < 1) ? 1 : $_GET['pg'];
$perpage	= $Gallery->setting('image_perpage');

#----------------------------
# Total albums
#----------------------------

	$query	= mysql_query('SELECT count(id) AS albums FROM  ' . $db_prefix . 'gallery_albums');
	$row	= mysql_fetch_assoc($query);
	
		$total = $row['albums'];
		$pages = @ceil($total / $perpage);
		
#----------------------------
# Calculate page links
#----------------------------

	$links = '';
	$comma = '';
	
	for ($i = 1; $i <= $pages; ++$i)
	{
		$links .= $space . '<a class="' . (($i == $page) ? 'page-active' : 'page') . '" href="' . $my_address . '?page=gallery&pg=' . $i . '">' . $i . '</a>';
		
		$space = ' ';
	}
	
$Gallery->template('pages/gallery/home.template.php')->hook('start', 1);

#----------------------------
# Get albums
#----------------------------

	$query = mysql_query('
		SELECT
			cat.*, cat_img.image
		
		FROM	
			' . $db_prefix . 'gallery_albums cat
			
			LEFT JOIN
				' . $db_prefix . 'gallery_albums_images cat_img
				ON cat.image = cat_img.id
				
		ORDER BY cat.name ASC
		
		LIMIT ' . ($page - 1) * $perpage . ', ' . $perpage
	);

$totalRows = @mysql_num_rows($query);
$count = 0;
while ($row = @mysql_fetch_assoc($query))
{
	$row = array_map('strip_slashes', $row);
	
	$row['r_image']	= '/uploads/gallery/albums/r_' . $row['image'];
	$row['image']	= '/uploads/gallery/albums/t_' . $row['image'];
	
	$Gallery->hook(2);
	
	++$count;
}
	
$Gallery->hook(3, 'end');
?>
